home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / SimpleHSprite.src < prev    next >
Encoding:
Text File  |  1995-11-11  |  14.2 KB  |  535 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \                SIMPLE HARDWARE SPRITE DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple HeliOS single
  9.   \ playfield display and generate a simple hardware sprite.
  10.   \
  11.   \ An IFF file is loaded and displayed, and the hardware sprite
  12.   \ is moved around the screen using the mouse.
  13.   \
  14.   \ Press <Space> to quit when finished.
  15.   \
  16.   \ ***********************************************************
  17.  
  18.  
  19.   \ ***********************************************************
  20.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  21.   \ ***********************************************************
  22.  
  23.   \ This should always be used at the start of any program which
  24.   \ is to be repeatedly recompiled.
  25.  
  26.   FORGET **CORE**
  27.  
  28.   \ *************************
  29.   \ Load include symbol files
  30.   \ *************************
  31.   \
  32.   \ These "include files" are pre-compiled (for speed) versions of the
  33.   \ Amiga includes and the Helios system includes.
  34.   \
  35.   \ Uncomment the lines below for standalone compilation, but otherwise
  36.   \ it is better to set these include files from the Helios Forth menus
  37.  
  38.   AMIGAINCLUDE HeliOS:HeliOS_AmigaInclude
  39.   USERINCLUDE  HeliOS:HeliOS_UserInclude
  40.  
  41.   \ ****************************************
  42.   \ Create display imagery file name strings
  43.   \ ****************************************
  44.  
  45.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  46.   \
  47.   \ The pictures here will be loaded into each of the display BitMaps.
  48.   \
  49.  
  50.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic2$
  51.  
  52.   \ **************************************
  53.   \ Create display configuration constants
  54.   \ **************************************
  55.   \
  56.   \ Collect all "display-specific" parameters here and generate "named"
  57.   \ constants which make references easier than using numeric values.
  58.   \
  59.   \ Collecting these together here makes it easier to adjust things at any
  60.   \ time without having to search source code to replace values individually.
  61.   \
  62.  
  63.  
  64.   256                      CONSTANT DisplayHeight      \ Full PAL display
  65.   320                      CONSTANT DisplayWidth       \ Lores display
  66.   44                       CONSTANT DisplayTopLine     \ Display start
  67.  
  68.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  69.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=screenwidth
  70.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  71.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=Displayheight
  72.   0                        CONSTANT Slice1Mode         \ Lores
  73.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  74.  
  75.   \ The calculation below takes the number of bitplanes and calculates
  76.   \ how many colours this represents.
  77.   \
  78.   \ One bitplane gives two colours.
  79.   \
  80.   \ Each additional bitplane multiplies the number of colours by two.
  81.   \
  82.   \ Performing a single LSL operation on any number multipies by 2, so we
  83.   \ have a quick method of multiplying by two for our colour calculation.
  84.   \
  85.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  86.   \
  87.   \ e.g.                              2*2*2
  88.   \                                   ^ ^ ^
  89.   \                                   Total number of planes = 3
  90.   \
  91.   \
  92.   \ So, we take the first value two
  93.   \
  94.   \ e.g.                              2*2*2
  95.   \                                   ^
  96.   \                                  Initial start value of 2
  97.   \
  98.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  99.   \ more times.
  100.   \
  101.   \ e.g.                              2*2*2
  102.   \                                     ^ ^
  103.   \                                     Total planes minus one
  104.   \
  105.   \
  106.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  107.   \
  108.  
  109.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  110.  
  111.   \ ***********************
  112.   \ Error handling routines
  113.   \ ***********************
  114.  
  115.   \ This error handler allows all errors to be routed via a comprehensive
  116.   \ sequential closedown routine, which is associated with the HeliOS
  117.   \ system error handler word ERROR".
  118.   \
  119.   \ When ERROR" senses an error, it prints an associated error message
  120.   \ delimited by '"' characters, and then closes everything down using the
  121.   \ routine CLOSEDOWN below which you have supplied.
  122.   \
  123.   \ This simplifies errors checks to the use of a single word, ERROR", which
  124.   \ displays a text message and closes eveything down.
  125.   \
  126.  
  127.   0 VARIABLE (CLOSEDOWN)
  128.  
  129.   : ?CLOSEDOWNERROR
  130.  
  131.   IF
  132.     CR
  133.     CR
  134.     TYPE
  135.     CR
  136.     CR
  137.     ." Press <Space> to quit!"
  138.     CR
  139.     CR
  140.     WAITSPACE
  141.     (CLOSEDOWN) @EXECUTE
  142.     QUIT
  143.   ELSE
  144.     DDROP
  145.   THEN
  146.   ;
  147.  
  148.   LATESTCFA VARIABLE ERROR1
  149.  
  150.   \ ****************************************
  151.   \ Create display pointer storage variables
  152.   \ ****************************************
  153.  
  154.   \ Here we create a set of "pointers", initially set to a "null" value.
  155.   \
  156.   \ These "pointers" are set up as "long addresses" when various components
  157.   \ of the display system are allocated and initialised.
  158.   \
  159.   \ Note that initially these are all set to zero, and we clear them back
  160.   \ to zero when we de-allocate the associated resource.
  161.   \
  162.   \ These DPOINTERs are all initially set to "null" by using '0.'.
  163.   \
  164.   \ When we allocate memory or Amiga system resources in the program at
  165.   \ run-time, these pointers are updated to contain the 32-bit address
  166.   \ of the newly allocated resource.
  167.   \
  168.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  169.   \ represent the associated address.
  170.  
  171.   0. DPOINTER Display1             \ Main Display structure pointer
  172.   0. DPOINTER Slice1               \ Slice 1 Slice structure pointer
  173.  
  174.   0. DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  175.  
  176.   0. DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  177.  
  178.   0. DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  179.  
  180.   0. DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  181.  
  182.   \ *************
  183.   \ Colour tables
  184.   \ *************
  185.  
  186.   \ Each colour entry requies 2 bytes of storage space
  187.  
  188.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  189.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  190.  
  191.   \ ***********************************
  192.   \ Create Display and Slice structures
  193.   \ ***********************************
  194.  
  195.   \ This routine simply makes blank structures, which then need to be
  196.   \ initialised later (in the CREATE_DISPLAY routine).
  197.  
  198.   : CREATE_DSLICES
  199.  
  200.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  201.  
  202.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  203.   ;
  204.  
  205.   : FREE_DSLICES
  206.  
  207.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  208.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  209.   ;
  210.  
  211.   \ ******************************
  212.   \ Create RasInfo structures etc.
  213.   \ ******************************
  214.  
  215.   : CREATE_RASINFO
  216.  
  217.   \ First allocate and initialise complete RasInfo structures.
  218.   \
  219.   \ This routine automatically allocates all BitMaps etc.
  220.   \
  221.  
  222.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  223.   DFLAG0= ERROR" Fail: RasInfo1"
  224.   Slice1_RasInfo MAKEPOINTER
  225.  
  226.   \ Set invisible area "sprite margins" for slice RasInfo
  227.  
  228.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  229.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  230.  
  231.   \ Store BitMap pointer - often useful for later reference
  232.  
  233.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  234.   ;
  235.  
  236.   : FREE_RASINFO
  237.  
  238.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  239.   ;
  240.  
  241.   \ ********************************
  242.   \ Create Display/Slice Copperlists
  243.   \ ********************************
  244.  
  245.   \ This function builds the main display copperlist by:
  246.   \
  247.   \ 1. Initialising the Slice data structure
  248.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  249.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  250.   \
  251.  
  252.   : CREATE_DISPLAY
  253.  
  254.   \ First initialise main display structures
  255.  
  256.   Slice1                           Display1  DS_Slice     INDEXD!L
  257.  
  258.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  259.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  260.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  261.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  262.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  263.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  264.  
  265.   \ Generate copper list information for each of the display slices
  266.  
  267.   Slice1 MAKECOPSTRIP
  268.   D0= ERROR" Fail: Slice1CopStrip"
  269.  
  270.   \ Make display
  271.  
  272.   Display1 MAKEDISPLAY
  273.   D0= ERROR" Fail: Display1"
  274.   ;
  275.  
  276.   : FREE_DISPLAY
  277.  
  278.   Display1                 FREEDISPLAY
  279.   Slice1                   FREECOPSTRIP
  280.   ;
  281.  
  282.   \ ********************************************************
  283.   \ Create SliceControl structures for double buffered slice
  284.   \ ********************************************************
  285.  
  286.   \ SliceControl structures are used to control any slices which perform
  287.   \ mapping or scrolling functions, or which require double or triple
  288.   \ playfield buffering.
  289.   \
  290.   \ In this case we have one slice which does not scroll, is not mapped,
  291.   \ but IS double buffered.
  292.   \
  293.  
  294.   : CREATE_SLICECONTROL
  295.  
  296.   \ Make SliceControl for double buffered bitmap display
  297.  
  298.   Slice1  0 0 MAKESLICECONTROL
  299.   DFLAG0= ERROR" Fail: SliceControl1"
  300.   Slice1_SliceControl MAKEPOINTER
  301.  
  302.   \ Install slice controls into HeliOS display control system
  303.  
  304.   Slice1_SliceControl  INSTALLSLICECONTROL
  305.   ;
  306.  
  307.   : FREE_SLICECONTROL
  308.  
  309.   CLEARSLICECONTROLS
  310.   Slice1_SliceControl  CLOSESLICECONTROL
  311.   ;
  312.  
  313.   \ These routines load an IFF picture into supplied BitMap, and correctly
  314.   \ initialises the supplied ColorTable.
  315.   \
  316.   \ The ColorTable is then used to create an initialised ColorMap structure.
  317.   \
  318.  
  319.   : CREATE_IMAGERY
  320.  
  321.   Slice1_BMap
  322.   Slice1_ColorTable
  323.   Slice1Pic
  324.   10 2 DOSLIB                        \ Call to internal HeliOS library
  325.   10 <> ERROR" Fail: Slice1Pic"
  326.  
  327.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  328.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  329.   Slice1_ColorMap MAKEPOINTER
  330.   ;
  331.  
  332.   : FREE_IMAGERY
  333.  
  334.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  335.   ;
  336.  
  337.   \ ****************************
  338.   \ Create hardware sprite image
  339.   \ ****************************
  340.  
  341.   \ This image uses the standard Amiga hardware sprite convention with
  342.   \ respect to the way bits are interpreted as colour information.
  343.  
  344.   CREATEL MyHSImage
  345.  
  346.   16 ,                   \ Width
  347.   5  ,                   \ Height
  348.  
  349.   BIN
  350.  
  351.   0000111111110000 ,     \ Row 1 first colour definition bits
  352.   0000111111110000 ,     \ Row 1 second colour definition bits
  353.  
  354.   0000110000110000 ,     \ Row 2 first colour definition bits
  355.   0000110000110000 ,     \ Row 2 second colour definition bits
  356.  
  357.   0000100110010000 ,     \ Row 3 first colour definition bits
  358.   1110100000010111 ,     \ Row 3 second colour definition bits
  359.  
  360.   0000110000110000 ,     \ Row 4 first colour definition bits
  361.   0000110000110000 ,     \ Row 4 second colour definition bits
  362.  
  363.   0000111111110000 ,     \ Row 5 first colour definition bits
  364.   0000111111110000 ,     \ Row 5 second colour definition bits
  365.  
  366.   DECIMAL
  367.  
  368.  
  369.   \ ***********************************
  370.   \ Create hardware sprite colour table
  371.   \ ***********************************
  372.  
  373.   \ This colour table simply specifies a few arbitrary colours which we
  374.   \ will then set into colour registers 16 to 31
  375.  
  376.   CREATEL MySpriteColourTable
  377.  
  378.   HEX
  379.  
  380.   0000 ,  \ Colour 16
  381.   0FFF ,  \ Colour 17
  382.   0AA0 ,  \ Colour 18
  383.   000F ,  \ Colour 19
  384.   0000 ,  \ Colour 20
  385.   000F ,  \ Colour 21
  386.   00F0 ,  \ Colour 22
  387.   0F00 ,  \ Colour 23
  388.   0000 ,  \ Colour 24
  389.   0004 ,  \ Colour 25
  390.   0040 ,  \ Colour 26
  391.   0400 ,  \ Colour 27
  392.   0000 ,  \ Colour 28
  393.   0008 ,  \ Colour 29
  394.   0080 ,  \ Colour 30
  395.   0800 ,  \ Colour 31
  396.  
  397.   DECIMAL
  398.  
  399.   \ ************************
  400.   \ Allocate a pointer store
  401.   \ ************************
  402.  
  403.   0. DPOINTER  MyHSpriteData
  404.  
  405.   \ **********************
  406.   \ Set up hardware sprite
  407.   \ **********************
  408.  
  409.   \ First we set sprite colours 16 to 31
  410.   \ Then we create a hardware sprite definition block
  411.   \ Then we install the hardware sprite
  412.  
  413.   : SetupHSprite
  414.  
  415.   Slice1 MySpriteColourTable 16 16 SETSLICECOLOURS
  416.  
  417.   1 1 MyHSImage MAKEHSPRITEBLOCK MyHSpriteData MAKEPOINTER
  418.  
  419.   MyHSpriteData 1 HSPRITE_INSTALL
  420.   ;
  421.  
  422.   \ **************************
  423.   \ Close down hardware sprite
  424.   \ **************************
  425.  
  426.   \ First we remove the hardware sprite
  427.   \ Then we de-allocate the sprite definition
  428.  
  429.   : FREE_HSPRITE
  430.  
  431.   MyHSpriteData HSPRITE_REMOVE
  432.  
  433.   MyHSpriteData  DDUP FREEHSPRITEBLOCK  CLEARPOINTER
  434.   ;
  435.  
  436.   \ ********************************
  437.   \ Display and move hardware sprite
  438.   \ ********************************
  439.  
  440.   \ Switch on mouse position reporting
  441.   \ Switch off the HeliOS mouse pointer image
  442.   \ Repeatedly set the sprite to the current mouse pointer position
  443.  
  444.   : TestHSprite
  445.  
  446.   1 REPORTMOUSE
  447.   0 HELIOSMPOINTER
  448.  
  449.   BEGIN
  450.     0 MOUSEX MOUSEY 0 MyHSpriteData HSPRITE_PLACE
  451.     ?TERMINAL 32 =
  452.   UNTIL
  453.   ;
  454.  
  455.  
  456.   \ *********************
  457.   \ Close down everything
  458.   \ *********************
  459.  
  460.   : CLOSEDOWN
  461.  
  462.   FREE_HSPRITE
  463.   FREE_SLICECONTROL
  464.   FREE_DISPLAY
  465.   FREE_IMAGERY
  466.   FREE_RASINFO
  467.   FREE_DSLICES
  468.   RESETERROR"
  469.   ;
  470.  
  471.   LATESTCFA (CLOSEDOWN) !
  472.  
  473.   : TestDisplay          \ Start of program
  474.  
  475.   SCRCLR
  476.  
  477.   CR
  478.   ."        **********************************************************"
  479.   CR 6 FPENSET
  480.   ."                      SIMPLE HARDWARE SPRITE DEMO"
  481.   CR 1 FPENSET
  482.   ."        **********************************************************"
  483.   CR
  484.   CR
  485.   ."        This code demonstrates how to create a simple HeliOS single"
  486.   CR
  487.   ."        playfield display and generate a simple hardware sprite."
  488.   CR
  489.   CR
  490.   ."        An IFF file is loaded and displayed, and the hardware"
  491.   CR
  492.   ."        sprite can then be moved around using the mouse."
  493.   CR
  494.   CR
  495.   ."        Press <Space> to quit demo."
  496.   CR
  497.   CR
  498.   ."        **********************************************************"
  499.   CR 6 FPENSET
  500.   ."                  Press <Space> or <L-Mouse> to see Demo          "
  501.   CR 1 FPENSET
  502.   ."        **********************************************************"
  503.   CR
  504.  
  505.   WAITSPACE
  506.  
  507.   SCRCLR
  508.  
  509.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  510.  
  511.   CREATE_DSLICES
  512.   CREATE_RASINFO
  513.   CREATE_IMAGERY
  514.   CREATE_DISPLAY
  515.   CREATE_SLICECONTROL
  516.  
  517.   SetupHSPrite
  518.  
  519.   HeliOS_On
  520.  
  521.   1 FrameRate !L
  522.  
  523.   Display1 SHOWDISPLAY
  524.  
  525.   TestHSprite
  526.  
  527.   HeliOS_Off
  528.  
  529.   0 REPORTMOUSE
  530.  
  531.   CLOSEDOWN
  532.   ;
  533.  
  534.   TestDisplay
  535.